package com.light.buttons;

import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.modifier.LoopEntityModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.hardware.SensorEventListener;

import com.light.gamecomponents.IGameComponents;
import com.light.roller.Direction;

public abstract class Button implements SensorEventListener, IUpdateHandler, IGameComponents{
	public enum ButtonState { CONTROLABLE, NOT_CONTROLABLE, PANEL_SHOWED, MENU_SHOWED };
	protected TextureRegion m_textureRegion;

	protected BaseGameActivity m_game;
	protected Sprite m_sprite;
	protected Direction m_direction;
	protected ButtonState m_state = ButtonState.CONTROLABLE;
	protected LoopEntityModifier m_nowModifiler;
	public void setState(ButtonState state) { m_state = state; }

	protected static final float[] SIZE = { 0.7f, 1.0f, 1.3f }; 
	public static int NOW_SIZE = 1;
	
	public Button(BaseGameActivity game)
	{
		m_game = game;
	}
	
	public abstract void initializeDirection(Direction direction);
	
	public abstract void setByCameraPosition(float x, float y);
	public ButtonState getState() { return m_state; }
	
	public void showButton()
	{
		if(m_sprite.getAlpha()==1)return;
		if (m_nowModifiler != null)
			m_sprite.unregisterEntityModifier(m_nowModifiler);
		LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(1.0f,m_sprite.getAlpha(),1)));

		m_nowModifiler = EntityModifier;
		m_sprite.registerEntityModifier(m_nowModifiler);
	}
	
	public void greyButton()
	{
		//m_sprite.setColor(0.3f, 0.3f, 0.3f);
	}
	public void ungreyButton()
	{
		//m_sprite.setColor(1.0f, 1.0f, 1.0f);
	}
	
	public void hideButton()
	{
		if(m_sprite.getAlpha()==0)return;
		if (m_nowModifiler != null)
			m_sprite.unregisterEntityModifier(m_nowModifiler);
		LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(1.0f,m_sprite.getAlpha(),0)));

		m_nowModifiler = EntityModifier;
		m_sprite.registerEntityModifier(m_nowModifiler);
		this.setState(ButtonState.NOT_CONTROLABLE);
	}
	
	public void setScale(float size)
	{
		m_sprite.setScale(size, size);
	}
	

}
